//
//  LKMainViewController.swift
//  LKWeibo
//
//  Created by 罗锟 on 16/3/2.
//  Copyright © 2016年 andy. All rights reserved.
//

import UIKit

class LKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = LKTabBar()
        //readOnly属性不可以直接设置值 要使用KVC方式间接设置值
        
        self.setValue(tabBar, forKeyPath: "tabBar")
        
//      addChildViewController(<#T##childController: UIViewController##UIViewController#>)
        
        addChildViewController(LKHomeViewController(), imageNamed: "tabbar_home", title: "首页")
        
        addChildViewController(LKMessageViewController(), imageNamed: "tabbar_message_center", title: "消息")
        
        addChildViewController(LKDiscoveryViewController(), imageNamed: "tabbar_discover", title: "发现")
        
        addChildViewController(LKSelfViewController(), imageNamed: "tabbar_profile", title: "我")
        
        
    }

    private func addChildViewController(childController: UIViewController, imageNamed:String, title:String) {
        
        //设置标题
        childController.title=title
        
        //设置按钮的图片
        childController.tabBarItem.image=UIImage(named: imageNamed)?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.selectedImage=UIImage(named: "\(imageNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        //设置TabBar的字体
        let attr = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(attr, forState: .Selected)
        
        
        addChildViewController(UINavigationController(rootViewController: childController))
        
    }

}
